<?php
require_once('./class/Statistique.php');
require_once('./class/Association.php');
switch($_GET['action']){

    default:
        echo "Statistiques";
    break;

    case "topParticipant":
        $stats = Statistique::getTopMaxParticipation();
        $html = '<table class="tablesorter">
        			<thead>
        				<th>'._NOM_INDIVIDU_.'</th>
        				<th>'._PRENOM_INDIVIDU_.'</th>
        				<th>'._NB_PARTICIPATION_.'</th>
        			</thead><tbody>';
        $i = 0;
        foreach($stats as $s){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
            			<td>'.$s->nom.'</td>
            			<td>'.$s->prenom.'</td>
            			<td>'.$s->nb_participation.'</td>
            		</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "topEvenement":
        $stats = Statistique::getTopEvenementByNote();
        $html = '<table class="tablesorter">
            			<thead>
            				<th>'._NOM_EVENEMENT_.'</th>
            				<th>'._NOTE_MOYENNE_.'</th>
            			</thead><tbody>';
        $i = 0;
        foreach($stats as $s){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
                			<td>'.$s->nom.'</td>
                			<td>'.$s->avg_note.'</td>
                		</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;
        
    case "getFinanceForm":
        echo '<form action="?module=statistique&action=getFinance" method="post">
        		<table>
        			<tr>
        				<td>'._ASSOCIATION_.'</td>
        				<td>'.Association::generateSelect().'</td>
        			</tr>
        			<tr>
        			    <td>'._DATE_.'</td>
        			    <td><input type="text" name="date" class="datepicker" /></td>
        			</tr>
        		    <tr>
        		        <td colspan="2"><input type="submit" />
        		    </tr>
        		</table>
            </form>';
    break;
    
    case "getFinance":
        $finance = Statistique::getFinance($_POST['id_association'], $_POST['date']);
        $span = ($finance < 0) ? 'style="color: red"' : 'style="color: green"';
        echo _FINANCE_.' '._DE_.' '.Association::getAssociation($_POST['id_association'])->getNom().' '._AU_.' '.$_POST['date'].' : <span '.$span.'>'.$finance.'</span>';
        break;
        
    case "getTopFinanceForm":
           echo '<form action="?module=statistique&action=getTopFinance" method="post">
        		<table>
        			<tr>
        			    <td>'._DATE_.'</td>
        			    <td><input type="text" name="date" class="datepicker" /></td>
        			     <td><input type="submit" />
        			</tr>
        		</table>
            </form>';
    break;
    
    case "getTopFinance":
           $stats = Statistique::getTopFinance($_POST['date']);
           echo _TOP_FINANCE_.' '._AU_.' '.$_POST['date'].'
           <table class="tablesorter">
           <thead>
           <th>'._ASSOCIATION_.'</th>
           <th>'._FINANCE_.'</th>
           </thead><tbody>';
           foreach($stats as $stat){
               $a = Association::getAssociation($stat->id_association);
               $span = ($stat->finance < 0) ? 'style="color: red"' : 'style="color: green"';
               echo '<tr>
               			<td>'.$a->getNom().'</td>
               			<td><span '.$span.'>'.$stat->finance.'</span></td>
               		</tr>';
           }
           echo '</tbody></table>';
        break;

}
?>
